﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;
using Chenxin.Lib.Utility;

public partial class IntentMoneyDetail : PageBase
{
    string strRecordId = string.Empty;

    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (string.IsNullOrEmpty(Request.Params["BillId"]))
            {
                Response.Redirect("~/page/errorpage.aspx?msg=非法信息", true);
            }
            if (!IsPostBack)
            {
                strRecordId = Request.Params["BillId"].ToString().Trim();
                this.hidRecordId.Value = strRecordId;
                Chenxin.Lib.Business.Entity.t_Intention_BillGetedInfo model = Chenxin.Lib.Business.DAL.t_Intention_BillGetedInfo.GetModel(new Guid(strRecordId));
                BindTable(model);
            }
        }
        catch (Exception ex)
        {
            Response.Redirect("~/page/errorpage.aspx?msg=" + Server.UrlEncode(ex.Message) + "", true);
        }
    }

    private void BindTable(Chenxin.Lib.Business.Entity.t_Intention_BillGetedInfo model)
    {
        StringBuilder sb = new StringBuilder();

        string inorout = "";
        if (model.InOrOut == 1)
            inorout = "收款";
        else
            inorout = "转移";

        //意向金基本信息
        sb.Append("<table width=\"100%\" cellspacing=\"1\" class=\"tabsorternew table_archive\">");
        sb.Append("<thead>");
        sb.Append("<tr>");
        sb.Append("<th colspan=\"8\" style='text-align:center;'><span>意向金基本信息</span></th>");
        sb.Append("</tr>");
        sb.Append("</thead>");
        sb.Append("<tbody>");
        sb.Append("<tr>");
        sb.AppendFormat("<th style=\"text-align:right;\">意向书编号：</th><td colspan=\"3\">{0}</td><th style=\"text-align:right;\">单据编号：</th><td colspan=\"3\">{1}{2}</td>", model.IntentionCode, model.BillCode,model.Status==1?"":"<span style=\"color:Red;\">(已作废)</span>");
        sb.Append("</tr>");
        sb.Append("<tr>");
        sb.AppendFormat("<th style=\"text-align:right;\">"+inorout+"城市：</th><td>{0}</td><th style=\"text-align:right;\">"+inorout+"公司：</th><td>{1}</td><th style=\"text-align:right;\">"+inorout+"部门：</th><td>{2}</td><th style=\"text-align:right;\">"+inorout+"人员：</th><td>{3}</td>", model.GetedCity,model.GetedCompany,model.GetedDepart, model.GetedEmployee);
        sb.Append("</tr>");
        sb.Append("<tr>");
        sb.AppendFormat("<th style=\"text-align:right;\">账号类型：</th><td>{0}</td><th style=\"text-align:right;\">账号银行：</th><td>{1}</td><th style=\"text-align:right;\">账号号码：</th><td colspan=\"3\">{2}</td>", model.AccountType==10?"公司账户":"授权账户", model.AccountBank.Length>0?model.AccountBank:"--",model.AccountNum.Length>0?model.AccountNum:"--");
        sb.Append("</tr>");
        sb.Append("<tr>");
        sb.AppendFormat("<th style=\"text-align:right;\">" + inorout + "金额：</th><td>{0}</td><th style=\"text-align:right;\">" + inorout + "时间：</th><td>{1:yyyy-MM-dd}</td>", model.GetedMoney, model.GetedTime);
        if (model.InOrOut == 0)
        {
            string payto = "";
            switch (model.PayTo)
            {
                case 10:
                    payto = "转定金";
                    break;
                case 20:
                    payto = "转房款";
                    break;
                case 30:
                    payto = "退还客户";
                    break;
                case 40:
                    payto = "转佣金";
                    break;
                default:
                    payto = "--";
                    break;
            }
            sb.AppendFormat("<th style=\"text-align:right;\">转移去向：</th><td>{0}</td><th style=\"text-align:right;\">代保管：</th><td>{1}</td>", payto, model.bCustody == 10 ? "是" : "否");
        }
        else
            sb.Append("<td colspan=\"4\"></td>");
        sb.Append("</tr>");
        sb.Append("<tr>");
        sb.AppendFormat("<th style=\"text-align:right;\">"+inorout+"确认：</th><td>{0}</td><th style=\"text-align:right;\">确认人：</th><td>{1}</td><th style=\"text-align:right;\">确认时间：</th><td colspan=\"3\">{2}</td>", model.IsConfirmed ? "已确认" : "否", model.ConfirmEmployee.Length>0?model.ConfirmEmployee:"--", model.ConfirmDate.ToString().Length>0?DateTime.Parse(model.ConfirmDate.ToString()).ToShortDateString():"--");
        sb.Append("</tr>");
        sb.Append("<tr>");
        sb.AppendFormat("<th style=\"text-align:right;\">" + inorout + "复核：</th><td>{0}</td><th style=\"text-align:right;\">复核人：</th><td>{1}</td><th style=\"text-align:right;\">复核时间：</th><td colspan=\"3\">{2}</td>", model.IsConfirmed ? "已确认" : "否", model.ConfirmEmployee.Length > 0 ? model.ConfirmEmployee : "--", model.ConfirmDate.ToString().Length > 0 ? DateTime.Parse(model.ConfirmDate.ToString()).ToShortDateString() : "--");
        sb.Append("</tr>");
        sb.Append("</tbody>");
        sb.Append("</table>");
        sb.Append("<div class=\"clear\" style=\"height:10px\"></div>");

        if (model.InOrOut == 1)
        {
            //意向金款项明细
            sb.Append("<table width=\"100%\" cellspacing=\"1\" class=\"tabsorternew table_archive\">");
            sb.Append("<thead>");
            sb.Append("<tr>");
            sb.Append("<th colspan=\"5\" style='text-align:center;'><span>意向金收款明细</span></th>");
            sb.Append("</tr>");
            sb.Append("</thead>");
            sb.Append("<tbody>");
            sb.Append("<tr>");
            sb.AppendFormat("<th style=\"text-align:center;width:15%;\">支付方式</th><th style=\"text-align:center;width:15%;\">支付金额</th><th style=\"text-align:center;width:15%;\">付款方名称</th><th style=\"text-align:center;width:15%;\">付款方账户</th><th style=\"text-align:center;\">备注</th>");
            sb.Append("</tr>");

            //获得意向金款项List
            List<Chenxin.Lib.Business.Entity.t_Intention_BillItemsInfo> itemslist = Chenxin.Lib.Business.DAL.t_Intention_BillItemsInfo.GetListArray(" BillId='" + model.BillId + "'");
            if (itemslist.Count < 1)
            {
                sb.Append("<tr><td colspan=\"5\" style='text-align:center;'>无款项明细记录</td></tr>");
            }
            else
            {
                foreach (Chenxin.Lib.Business.Entity.t_Intention_BillItemsInfo item in itemslist)
                {
                    sb.Append("<tr>");
                    sb.AppendFormat("<td style=\"text-align:center;\">{0}</td><td style=\"text-align:center;\">{1}</td><td style=\"text-align:center;\">{2}</td><td style=\"text-align:center;\">{3}</td><td>{4}</td>", item.PayMode, item.PayMoney, item.PayName, item.PayCode, item.PayMemo);
                    sb.Append("</tr>");
                }
            }
            sb.Append("</tbody>");
            sb.Append("</table>");
            sb.Append("<div class=\"clear\" style=\"height:10px\"></div>");
        }

        this.ltArchiveDetailInfo.Text = sb.ToString();
    }
}
